<template>
	<popup ref="appUpdate" class="app-update">
		<view class="update" @touchmove.stop.prevent>
			<text class="iconfont icon-guanbi" @tap="$refs.appUpdate.close()"></text>
			<image class="update-img" src="@/static/images/common/update.png"></image>
			<view class="update-box">
				<view class="update-box__title">发现新版本啦！</view>
				<view class="update-box__value">
					<scroll-view scroll-y="true" class="scroll-Y">
						{{ value || '基本更新' }}
					</scroll-view>
				</view>
				<view class="update-box__btn">
					<view class="btn-li close" @tap="close">{{
						cancelText ? cancelText : '不再提示'
					}}</view>
					<view class="btn-li go" @tap="goUpdate">立即更新</view>
				</view>
			</view>
		</view>
	</popup>
</template>

<script>
import Popup from '@/components/uni/Popup';
export default {
	components: {
		Popup
	},
	props: {
		cancelText: {
			type: String,
			default: () => {
				return null;
			}
		}
	},
	data() {
		return {
			isShow: false,
			value: '',
			wgtUrl: '',
			params: {}
		};
	},

	mounted() {},

	methods: {
		// #ifdef APP-PLUS
		getServerNo(updateTip) {
			if (this.$store.state.common.appUpdate) {
				// uni.hideTabBar({});
				let that = this;
				const platform = uni.getSystemInfoSync().platform;
				if (uni.getSystemInfoSync().platform == 'android') {
					this.params.os = 1;
				} else if (uni.getSystemInfoSync().platform == 'ios') {
					this.params.os = 0;
				}
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
					that.params.version = widgetInfo.version;
					that.$service.common.version
						.latestV(that.params)
						.then(res => {
							if (updateTip === 1) {
								that.$refs.appUpdate.open();
								that.$store.state.common.appUpdate = false;
								that.wgtUrl = res.url;
								that.value = res.note;
							} else {
								if (res.status === 1 && res.updateTip === 1) {
									that.$refs.appUpdate.open();
									that.$store.state.common.appUpdate = false;
									that.wgtUrl = res.url;
									that.value = res.note;
								} else {
									that.$refs.appUpdate.close();
								}
							}

						})
						.catch(err => {
							uni.showToast({
								title: err.message,
								icon: 'none'
							});
						});
				});
			}
		},
		close() {
			uni.setStorageSync('updateInfo', {
				showUpdate: 'false',
				version: this.params.version
			});
			this.$refs.appUpdate.close();
		},
		goUpdate() {
			plus.runtime.openURL(this.wgtUrl);
			this.$refs.appUpdate.close();
		}
		// #endif
	}
};
</script>
<style lang="scss" scoped>
.app-update {
	.update {
		width: 564rpx;
		margin-top: -100rpx;
		position: relative;
		.iconfont {
			position: absolute;
			right: 0rpx;
			top: 20rpx;
			font-size: 40rpx;
			color: #fff;
			z-index: 10;
		}
		.update-img {
			width: 100%;
			height: 264rpx;
		}
		.update-box {
			background: #ffffff;
			height: 400rpx;
			width: 100%;
			padding-bottom: 20rpx;
			margin-top: -20rpx;
			border-radius: 16rpx;
			overflow: hidden;
			&__title {
				margin-top: 10rpx;;
				text-align: center;
				color: #fc3e3e;
				font-size: 36rpx;
			}
			&__value {
				color: #333333;
				font-size: 28rpx;
				padding: 0 40rpx;
				height: 182rpx;
				margin-top: 24rpx;
				.scroll-Y {
					width: 100%;
					height: 100%;
				}
			}
			&__btn {
				@include flexBox(space-around, center);
				margin-top: 40rpx;
				.btn-li {
					width: 240rpx;
					height: 68rpx;
					border-radius: 32px;
					text-align: center;
					line-height: 68rpx;
					font-size: 28rpx;
					color: #ffffff;
					&.close {
						background: #d8d8d8;
					}
					&.go {
						background: #ff4444;
					}
				}
			}
		}
	}
}
</style>
